#include<iostream>
#include"EquationSolver.h"

class myf_1 : public Function
{
public:
  double operator()(double x){
    return sin(x/2)-1;
  }
};
 class myf_2 : public Function
{
public:
  double operator()(double x){
    return exp(x)-tan(x);
  }
};
class myf_3 : public Function
{
public:
  double operator()(double x){
    return x*x*x-12*x*x+3*x+1;
  }
};
int main(void){
 

  double epsi = std::numeric_limits<double>::epsilon();
  myf_1 f_1;
  myf_2 f_2;
  myf_3 f_3;
  Secant<myf_1> Sec_1(0, acos(-1)/2, 50, epsi, f_1);
  Secant<myf_2> Sec_2(1, 1.4, 50, epsi, f_2);
  Secant<myf_3> Sec_3(0, -0.5, 50, epsi, f_3);
  double *R_1 = Sec_1.solve();
  double *R_2 = Sec_2.solve();
  double *R_3 = Sec_3.solve();
  std::cout<<"第一小题的结果为："<<"根为"<<R_1[0]<<",迭代次数为"<<R_1[1]<<",误差为"<<f_1(R_1[0])<<std::endl;
  std::cout<<"*******************************************************"<<std::endl;
  std::cout<<"第二小题的结果为："<<"根为"<<R_2[0]<<",迭代次数为"<<R_2[1]<<",误差为"<<f_2(R_2[0])<<std::endl;
  std::cout<<"*******************************************************"<<std::endl;
  std::cout<<"第三小题的结果为："<<"根为"<<R_3[0]<<",迭代次数为"<<R_3[1]<<",误差为"<<f_3(R_3[0])<<std::endl;

  return 0;
}
